package com.piesat.quake.business.device.mqtt.writer;

import com.piesat.quake.business.device.mqtt.param.ParseParam;

import io.netty.buffer.ByteBuf;

/**
 * 数字类型写入器
 *
 * @author Gersy
 * @date 2023/2/6
 * @since 1.0
 */
public class IpWriter implements Writer {

    @Override
    public void write(ByteBuf byteBuf, ParseParam numberParam, Object value) {
        String ip = (String) value;
        String[] numbers = ip.split("\\.");
        for (String number : numbers) {
            short b = Short.parseShort(number);
            byteBuf.writeByte((byte)(b & 0xFF));
        }
    }
}
